/**
 * jims
 */
package com.jims.master.modules.drug.service;


import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.common.utils.IdGen;
import com.jims.master.modules.drug.dao.DrugSupplierCataDao;
import com.jims.master.modules.drug.entity.DrugSupplierCata;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 药品厂商Entity
 * @author DT
 * @version 2017-03-01
 */
@Service
@Transactional(readOnly = true)
public class DrugSupplierCataService extends CrudService<DrugSupplierCataDao, DrugSupplierCata> {

	public DrugSupplierCata get(String id) {
		return super.get(id);
	}

	/**
	 * 药品基本信息调用厂商自动补全方法
	 * @param drugSupplierCata
	 * @param q
	 * @param limit
	 * @return
	 * @author CTQ
	 * @date 2017-03-09 15:08:59
	 */
	public List<DrugSupplierCata> findAutoCompleteList(DrugSupplierCata drugSupplierCata,String q,String limit,String supplierClass) {
		return dao.findAutoCompleteList(drugSupplierCata, q, limit,supplierClass);
	}
	
	public Page<DrugSupplierCata> findPage(Page<DrugSupplierCata> page, DrugSupplierCata drugSupplierCata) {
		return super.findPage(page, drugSupplierCata);
	}
	
	@Transactional(readOnly = false)
	public int save(DrugSupplierCata drugSupplierCata) {
        int num = 0;
        if(null == drugSupplierCata.getId() || drugSupplierCata.getId().trim().equals("")){
            drugSupplierCata.preInsert();
            drugSupplierCata.setId(IdGen.uuid());
            num = dao.insert(drugSupplierCata);
        }else{
            drugSupplierCata.preUpdate();
            num = dao.update(drugSupplierCata);
        }
		return num;
	}
	
	@Transactional(readOnly = false)
	public int delete(DrugSupplierCata drugSupplierCata) {
		return super.delete(drugSupplierCata);
	}

	public List<DrugSupplierCata> getListBySupplierName(String supplierName,String id){
		return dao.getListBySupplierName(supplierName,id);
	}
}